import 'package:flutter/material.dart';
import 'package:love_app/common/su.dart';
import 'package:love_app/pages/chat_page/chat_ui/chat_content.dart';
import 'package:love_app/providers/norify_update/chat_input_update_provider.dart';
import 'package:love_app/providers/norify_update/chat_sent_icon_provider.dart';
import 'package:love_app/providers/share_provider.dart';
import 'package:provider/provider.dart';

class ChatPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ShareProvider shareProvider =
        Provider.of<ShareProvider>(context, listen: false);
    return Scaffold(
      appBar: Su().appBar(
        "悄悄话",
        colors: shareProvider.themeColor,
      ),
      body: _bodys(shareProvider),
    );
  }

  Widget _body(ShareProvider shareProvider) {
    return Container(
      child: Provider<ChatSentIconProvider>.value(
        child: ChangeNotifierProvider.value(
          child: ChatContent(
            otherId: shareProvider.loverInfo.uid,
            otherImage: shareProvider.loverInfo.headimg,
          ),
          value: null,
        ),
        value: null,
      ),
    );
  }

  Widget _bodys(ShareProvider shareProvider) {
    return MultiProvider(
      // 聚合方式添加多个共享数据
      providers: [
        ChangeNotifierProvider<ChatSentIconProvider>(
          create: (_) => ChatSentIconProvider(),
        ),
        ChangeNotifierProvider<ChatInputUpdateProvider>(
          create: (_) => ChatInputUpdateProvider(),
        ),
      ],
      child: ChatContent(
        otherId: shareProvider.loverInfo.uid,
        otherImage: shareProvider.loverInfo.headimg,
      ),
    );
  }
}
